﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Billing.DataObjects;
using System.Linq;
namespace Billing.Transactions
{
    public partial class ClientsUnionForm : Billing.WindowsBase.FormBase
    {
        public ClientsUnionForm()
        {
            InitializeComponent();
        }

        ClientsView ClientFrom = null;
        ClientsView ClientTo = null;
        private void trvClientFrom_ChooseBootonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
        {
            Billing.Win.ClientsSelectionForm frm = new Billing.Win.ClientsSelectionForm(false);

            frm.AllowSelect = true;

            if (frm.ShowDialog() == DialogResult.OK)
            {
                ClientsView cv = (ClientsView)frm.SelectedObjects[0].CurrentObject;
            }
        }

        private void trvClientTo_ChooseBootonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
        {
            Billing.Win.ClientsSelectionForm frm = new Billing.Win.ClientsSelectionForm(false);

            frm.AllowSelect = true;

            if (frm.ShowDialog() == DialogResult.OK)
            {
                ClientsView cv = (ClientsView)frm.SelectedObjects[0].CurrentObject;
            }
        }
        public void OnSave()
        {
            if (ShowQuestion("დარწმუნებული ხართ, რომ  გსურთ ოპერაციის შესრულება?") == DialogResult.Yes)
            {
                try
                {

                    BillingDataContext context = new BillingDataContext();
                    context.ClientsUnion(ClientFrom.ID, ClientTo.ID, valDate.DateTime);
                    ShowInformation("ოპერაცია დასრულდა წარმატებით");
                }
                catch (Exception x)
                {
                    ShowError(x);
                }
            }
            if (this.Modal)
                this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            OnSave();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
